package org.ruanjj.majorityelement;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class Solution {
    public int majorityElement(int[] nums) {
        HashMap<String,Integer> hashMap = new HashMap<>();
        int count = 0;
        int res = 0;

        for(int n:nums){
            Integer value = hashMap.containsKey(String.valueOf(n))? hashMap.get(String.valueOf(n)):0;
            value++;
            hashMap.put(String.valueOf(n),value);
            if(value >= count){
                count = value;
                res = n;
            }
        }

        return res;
    }
}
